package cate.game.play.buff.h;

import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.round.RoundCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.effect.SkillEffect;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 有队友存活时，被单体技能攻击时额外提升闪避 （同时会替换主动技能）
 */
public class 潜行BH extends BuffHandler {

	private FightAttr 临时属性;
	private List<Integer> 原始技能;
	private List<Integer> 替换技能;

	//临时属性=11:1000&原始技能=101#102#103&替换技能=201#202#203
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		临时属性 = new FightAttr(args.get("临时属性"));
		原始技能 = args.getIntList("原始技能");
		替换技能 = args.getIntList("替换技能");

		if(XT.isBlank(原始技能)||XT.isBlank(替换技能)){
			return;
		}
		if(原始技能.size()!=替换技能.size()){
			return;
		}
		for (int i = 0; i < 原始技能.size(); i++) {
			replaceMap.put(原始技能.get(i), 替换技能.get(i));
		}
	}

	private Map<Integer,Integer> replaceMap = new HashMap<>();

	@Override
	public void beforeSkillSettleAsTarget(SkillActionCtx action, SkillEffect effect) {
		if (action.getSkill().getTargetNum() != 1) {
			return;
		}
		if (!action.getSkill().cfg.isHurtSkill()){
			return;
		}
		effect.getTargetCtx(buff.owner).addTargetAttr(临时属性);
	}

	@Override
	public Skill handleReplace(RoundCtx round, Skill oldSkill) {
		Integer replaceId = replaceMap.get(oldSkill.tid);
		if (replaceId == null) {
			return null;
		}
		return round.getCfg().skill.buildById(buff.owner, replaceId);
	}
}
